package com.barbeque.mall.controller.wx;

import com.barbeque.mall.bean.BasePageInfo;
import com.barbeque.mall.bean.BaseRespVo;
import com.barbeque.mall.bean.BaseRespVoNoData;
import com.barbeque.mall.bean.order.MarketOrderGoods;
import com.barbeque.mall.bean.param.CommonData;
import com.barbeque.mall.bean.wx.order.*;
import com.barbeque.mall.service.wx.WxOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author Tezel
 * @since 2022/07/18 19:48
 */
@RestController
@RequestMapping("wx/order")
public class WxOrderController {

    @Autowired
    WxOrderService orderService;

    @RequestMapping("list")
    public BaseRespVo list(int showType , BasePageInfo pageInfo ){

        CommonData<WxOrderListVo> data = orderService.list(showType,pageInfo);

        return BaseRespVo.ok(data);

    }

    @RequestMapping("detail")
    public BaseRespVo detail(int orderId){

        WxOrderDetailVo data = orderService.detail(orderId);

        return BaseRespVo.ok(data);

    }

    //TODO 系统取消103

    @RequestMapping("cancel")
    public BaseRespVoNoData cancel(@RequestBody WxOrderCancelBo wxOrderCancelBo){

        orderService.cancel(wxOrderCancelBo);

        return BaseRespVoNoData.ok();

    }

    @RequestMapping("refund")
    public BaseRespVoNoData refund(@RequestBody WxOrderCancelBo wxOrderRefundBo){

        orderService.refund(wxOrderRefundBo);

        return BaseRespVoNoData.ok();

    }

    @RequestMapping("confirm")
    public BaseRespVoNoData confirm(@RequestBody WxOrderCancelBo wxOrderConfirmBo){

        orderService.confirm(wxOrderConfirmBo);

        return BaseRespVoNoData.ok();

    }

    @RequestMapping("goods")
    public BaseRespVo goods(Integer orderId,Integer goodsId){

        MarketOrderGoods data = orderService.goods(orderId,goodsId);

        return BaseRespVo.ok(data);

    }

    @RequestMapping("comment")
    public BaseRespVoNoData comment(@RequestBody WxOrderCommentBo wxOrderCommitBo){

        orderService.comment(wxOrderCommitBo);

        return BaseRespVoNoData.ok();

    }





    @RequestMapping("submit")
    public BaseRespVo commit(@RequestBody WxOrderCommitBo wxOrderCommitBo)  {

        WxOrderSubmitPo data = orderService.submit(wxOrderCommitBo);

        return BaseRespVo.ok(data);

    }

    @RequestMapping("prepay")
    public BaseRespVo prepay(@RequestBody Map map) {
        if(map.get("orderId").getClass() == Integer.class){
        Integer orderId = (Integer)  map.get("orderId");
            orderService.prepay(orderId);
        }

        return BaseRespVo.ok(null);
    }


}
